/* Copyright (c) 2010, David Kreuter. See LICENSE for more information */

extern "C"{
#include "headers.h"
}

/*int main(int argc, char **argv){
	// This code creates a byte-compatible copy of a narc.
	uint8 *buf; uint32 len; narc *n;
	if(argc<3)return 1;
	printf("Reading...  \n"); if(!read_file(argv[1],&buf,&len))return 2;
	printf("Parsing...  \n"); if(!(n=read_narc(buf,len))) return 3;
	printf("Rendering...\n"); if(!write_narc(n,buf,len)) return 4;
	printf("Writing...  \n"); if(!write_file(argv[2],&buf,&len))return 5;
	printf("DONE!\n");
	free(buf);
	free_narc(n);
}*/

/*int main(int argc, char **argv){
	// 1. read narc 2. read bmd 3. write bmd 4. write narc
	uint8 *buf, *buf2; uint32 len, len2; narc *n;
	if(argc<3)return 1;
	if(!read_file(argv[1],&buf,&len))return 2;
	if(!(n=read_narc(buf,len))) return 3;
	free(buf); len=0;
		if(!n)return 3;
		for(int i=0;i<n->num_files;i++){
			bmd *b=read_bmd(n->file[i],n->size[i]);
				if(!b)return 4;
				uint8 *buf2=(uint8*)malloc(len2=size_bmd(b));
				memset(buf2, 0xE2, len2);
				write_bmd(b,buf2,len2);
			save_file(n,i,buf2,len2);
			free_bmd(b);
		}
	buf=(uint8*)malloc(len=size_narc(n));
	if(!write_narc(n,buf,len)) return 5;
	if(!write_file(argv[2],&buf,&len))return 6;
	free_narc(n);
	free(buf); len=0;
	return 0;
}*/

/*int main(int argc, char **argv){
	if(argc<2)return 1;
	uint8 *buf; uint32 len;
	if(!read_file(argv[1],&buf,&len))return 2;
	narc *n=read_narc(buf,len);
	free(buf);
	if(!n)return 3;
	for(int i=0;i<n->num_files;i++){
		bmd *b=read_bmd(n->file[i],n->size[i]);
		free_bmd(b);
	}
	free_narc(n);
	return 0;
}*/

/*int main(int argc, char **argv){
	uint8 *buf=0; uint32 len;
	int argi=0;
	while(++argi<argc){
		if(!read_file(argv[argi],&buf,&len))continue;
		bmd *b=read_bmd(buf,len);
		free_bmd(b);
	}
	if(buf)free(buf);
	return 0;
}*/

int main(int argc, char **argv){
	// 1. read bmd 2. write bmd
	uint8 *buf; uint32 len; bmd *b;
	if(argc<3)return 1;
	if(!read_file(argv[1],&buf,&len))return 2;
		b=read_bmd(buf,len);
		if(!b)return 3;
		free(buf); buf=(uint8*)malloc(len=size_bmd(b));
		memset(buf,0xE2,len);
		write_bmd(b,buf,len);
		free_bmd(b);
	if(!write_file(argv[2],&buf,&len))return 4;
	free(buf);
	return 0;
}
